package com.sheyu.mall.search.controller;

import com.sheyu.mall.search.service.MallSearchService;
import com.sheyu.mall.search.vo.SearchParam;
import com.sheyu.mall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * @author sheyu
 * @date 2020/8/16 5:38 下午
 */

@Controller
public class SearchController {

    @Autowired
    MallSearchService mallSearchService;

    /**
     *
     * {
     *     "query":
     *     {
     *         "bool":{
     *             "must":[
     *              {
     *                  "match":{
     *                      "skuTitle":"华为"
     *                  }
     *              }
     *             ],
     *             "filter":[
     *             {
     *                 "term":{
     *                     "catalogId":"225"
     *                 }
     *             },
     *             {
     *                 "terms":{
     *                     "bradId":[
     *                     "1","2","9"
     *                     ]
     *                 }
     *             },
     *             {
     *                 "nested":{
     *                    "path":"attrs",
     *                    "query": {
     *                     "bool":{
     *                         "must":[
     *                             "term":{
     *                                 "attrs.attrId":{
     *                                     "value":"15"
     *                                 }
     *                             },
     *                             {
     *                                 "terms":{
     *                                     "attr.attrValue":[
     *                                         "value1",
     *                                         "value2"
     *                                     ]
     *                                 }
     *                             }
     *                         ]
     *                     }
     *                    }
     *                 }
     *             },
     *             {
     *                 "term":{
     *                     "hasStock":{
     *                         "value":"true"
     *                     }
     *                 }
     *             },
     *             {
     *                 "range":{
     *                     "skuPrice":{
     *                         "gte":0,
     *                         "lte":6000
     *                     }
     *                 }
     *             }
     *             ]
     *         }
     *     },
     *     "sort":[
     *      {
     *          "skuPrice":{
     *              "order":"desc"
     *          }
     *      }
     *     ]
     *    "from":0,
     *    "size":1,
     *    "highlight":{
     *          "fields":{"skuTitle":{}},
     *        "pre_tags":"<b style='color:red'>",
     *        "post_tags":"</b>"
     *    }
     * }
     *
     * 模糊匹配，过滤（按属性,分类,品牌,价格区间，库存)，排序，分页，高亮，聚合分析
     *
     *
     *
     *
     * @param searchParam
     * @param model
     * @return
     */
    @GetMapping("/list.html")
    public String ListPage(SearchParam searchParam, Model model){

        //根据传过来过的数据查询结果
        SearchResult result = mallSearchService.search(searchParam);
        model.addAttribute("result",result);
        return "list";
    }
}
